﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class DanhMucChinh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int intId = -1;

        if (Request.QueryString["id"] != null)
        {
            intId = Int32.Parse(Request.QueryString["id"]);
        }
        else
        {
            return;
        }

        LinQ_RaoVatDataContext linQ = new LinQ_RaoVatDataContext();

        var query = from DANH_MUC_CON in linQ.DANH_MUC_CONs where DANH_MUC_CON.MaDanhMucChinh == intId && DANH_MUC_CON.Deleted == false orderby DANH_MUC_CON.TenDanhMucCon ascending select DANH_MUC_CON;        
        var KiemTraDMC = from DanhMucChinh in linQ.DANH_MUC_CHINHs 
                         where DanhMucChinh.MaDanhMucChinh == intId && DanhMucChinh.Deleted == false 
                         select DanhMucChinh;

        GridView1.DataSource = query;
        GridView1.DataBind();
        
           var DanhSachTinRaoVat = from DanhMucCon in linQ.DANH_MUC_CONs
                                    from TinRaoVat in linQ.TIN_RAO_VATs
                                    where DanhMucCon.Deleted == false && DanhMucCon.MaDanhMucChinh == intId && TinRaoVat.MaDanhMucCon == DanhMucCon.MaDanhMucCon && TinRaoVat.Deleted == false
                                    orderby TinRaoVat.ThoiGianDang descending
                                    select TinRaoVat;
            danhsach.ListTinRaoVat = DanhSachTinRaoVat.ToList();           
        }
       
    
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DANH_MUC_CON objTin = (DANH_MUC_CON)e.Row.DataItem;
            HyperLink hplTenDanhMucCon = (HyperLink)e.Row.FindControl("hplTenDanhMucCon");
            hplTenDanhMucCon.Text = objTin.TenDanhMucCon;
            hplTenDanhMucCon.NavigateUrl = "~/RaoVat/DanhSachTinRaoVatThuocDanhMucCon.aspx?id=" + objTin.MaDanhMucCon;
        }
    }
   
    
  

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        int intId = -1;

        if (Request.QueryString["id"] != null)
        {
            intId = Int32.Parse(Request.QueryString["id"]);
        }
        else
        {
            return;
        }
        LinQ_RaoVatDataContext linQ = new LinQ_RaoVatDataContext();

        var query = from DANH_MUC_CON in linQ.DANH_MUC_CONs where DANH_MUC_CON.MaDanhMucChinh == intId orderby DANH_MUC_CON.TenDanhMucCon ascending select DANH_MUC_CON;
        GridView1.DataSource = query;
        GridView1.DataBind();
    }

    protected void lbtDangBaiRaoVat_Click(object sender, EventArgs e)
    {

    }
}
